home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / EXAMPLES / IDRAW / SLPOLYGO.C < prev    next >
C/C++ Source or Header  |  1992-01-17  |  6KB  |  166 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. // $Header: slpolygons.c,v 1.10 89/10/09 14:49:38 linton Exp $
  24. // implements classes RectSelection and PolygonSelection.
  25.  
  26. #include "ipolygons.h"
  27. #include "rubbands.h"
  28. #include "slpolygons.h"
  29. #include <iostream.h>
  30.  
  31. // RectSelection creates the rectangle's filled interior and outline.
  32.  
  33. RectSelection::RectSelection (Coord l, Coord b, Coord r, Coord t, Graphic* gs)
  34. : (gs) {
  35.     myname = "Rect";
  36.     Append(new IFillRect(l, b, r, t));
  37.     Append(new Rect(l, b, r, t));
  38. }
  39.  
  40. // RectSelection reads data to initialize its graphic state and create
  41. // its filled interior and outline.
  42.  
  43. RectSelection::RectSelection (istream& from, State* state) : (nil) {
  44.     myname = "Rect";
  45.     ReadGS(from, state);
  46.     Skip(from);
  47.     Coord l, b, r, t;
  48.     from >> l >> b >> r >> t;
  49.     Append(new IFillRect(l, b, r, t));
  50.     Append(new Rect(l, b, r, t));
  51. }
  52.  
  53. // Copy returns a copy of the RectSelection.
  54.  
  55. Graphic* RectSelection::Copy () {
  56.     Coord l, b, r, t;
  57.     GetOriginal2(l, b, r, t);
  58.     return new RectSelection(l, b, r, t, this);
  59. }
  60.  
  61. // GetOriginal2 returns the two corners that were passed to the
  62. // RectSelection's constructor.
  63.  
  64. void RectSelection::GetOriginal2 (Coord& l, Coord& b, Coord& r, Coord& t) {
  65.     ((Rect*) Last())->GetOriginal(l, b, r, t);
  66. }
  67.  
  68. // GetOriginal returns the two corners that were passed to the
  69. // RectSelection's constructor plus the other two opposite corners.
  70.  
  71. int RectSelection::GetOriginal (const Coord*& x, const Coord*& y) {
  72.     static Coord sx[4], sy[4];
  73.     GetOriginal2(sx[0], sy[0], sx[2], sy[2]);
  74.     sx[1] = sx[0];
  75.     sy[1] = sy[2];
  76.     sx[3] = sx[2];
  77.     sy[3] = sy[0];
  78.     x = sx;
  79.     y = sy;
  80.     return 4;
  81. }
  82.  
  83. // WriteData writes the RectSelection's data and Postscript code to
  84. // draw it.
  85.  
  86. void RectSelection::WriteData (ostream& to) {
  87.     Coord l, b, r, t;
  88.     GetOriginal2(l, b, r, t);
  89.     to << "Begin " << startdata << " Rect\n";
  90.     WriteGS(to);
  91.     to << startdata << "\n";
  92.     to << l << " " << b << " " << r << " " << t << " Rect\n";
  93.     to << "End\n\n";
  94. }
  95.  
  96. // CreateRubberVertex creates and returns the right kind of
  97. // RubberVertex to represent the RectSelection's shape.
  98.  
  99. RubberVertex* RectSelection::CreateRubberVertex (Coord* x, Coord* y,
  100. int n, int rubpt) {
  101.     return new RubberPolygon(nil, nil, x, y, n, rubpt);
  102. }
  103.  
  104. // CreateReshapedCopy creates and returns a reshaped copy of itself
  105. // using the passed points and its graphic state.  It returns a
  106. // PolygonSelection because the points may not shape a rect any more.
  107.  
  108. Selection* RectSelection::CreateReshapedCopy (Coord* x, Coord* y, int n) {
  109.     return new PolygonSelection(x, y, n, this);
  110. }
  111.  
  112. // PolygonSelection creates the polygon's filled interior and outline.
  113.  
  114. PolygonSelection::PolygonSelection (Coord* x, Coord* y, int n, Graphic* gs)
  115. : (gs) {
  116.     myname = "Poly";
  117.     Append(new IFillPolygon(x, y, n));
  118.     Append(new GPolygon(x, y, n));
  119. }
  120.  
  121. // PolygonSelection reads data to initialize its graphic state and
  122. // create its filled interior and outline.
  123.  
  124. PolygonSelection::PolygonSelection (istream& from, State* state) : (nil) {
  125.     myname = "Poly";
  126.     ReadGS(from, state);
  127.     Coord* x;
  128.     Coord* y;
  129.     int n;
  130.     ReadPoints(from, x, y, n);
  131.     Append(new IFillPolygon(x, y, n));
  132.     Append(new GPolygon(x, y, n));
  133. }
  134.  
  135. // Copy returns a copy of the PolygonSelection.
  136.  
  137. Graphic* PolygonSelection::Copy () {
  138.     Coord* x;
  139.     Coord* y;
  140.     int n = GetOriginal(x, y);
  141.     Graphic* copy = new PolygonSelection(x, y, n, this);
  142.     return copy;
  143. }
  144.  
  145. // GetOriginal returns the vertices that were passed to the
  146. // PolygonSelection's constructor.
  147.  
  148. int PolygonSelection::GetOriginal (const Coord*& x, const Coord*& y) {
  149.     return ((GPolygon*) Last())->GetOriginal(x, y);
  150. }
  151.  
  152. // CreateRubberVertex creates and returns the right kind of
  153. // RubberVertex to represent the PolygonSelection's shape.
  154.  
  155. RubberVertex* PolygonSelection::CreateRubberVertex (Coord* x, Coord* y,
  156. int n, int rubpt) {
  157.     return new RubberPolygon(nil, nil, x, y, n, rubpt);
  158. }
  159.  
  160. // CreateReshapedCopy creates and returns a reshaped copy of itself
  161. // using the passed points and its graphic state.
  162.  
  163. Selection* PolygonSelection::CreateReshapedCopy (Coord* x, Coord* y, int n) {
  164.     return new PolygonSelection(x, y, n, this);
  165. }
  166.